<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        div {
            width: 400px;
            height: 400px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }

        div section {
            font-weight: 700;
        }

        div input {
            height: 30px;
            width: 150px;
            margin: 20px 0;
            outline: none;
        }
    </style>
</head>

<body>
    <div>
        <section>登录页面</section>
        <input type="text" placeholder="请输入用户名">
        <input type="password" placeholder="请输入密码">
        <input type="button" value="登录">
    </div>
    <script src="./ajax.js"></script>
    <script>
        let inp = document.querySelectorAll('input')
        inp[2].onclick = function () {
            if (/^\d{4}$/.test(inp[1].value)) {
                ajax('get', 'https://yantianfeng.com/api/login', {
                    username: inp[0].value,
                    password: inp[1].value,
                }, function (data) {
                    if(data.status == 200){
                        alert('登录成功')
                    }
                })
            } else {
                alert('请输入密码')
            }

        }
    </script>
</body>

</html>